package com.example.mall.web.controller;

import com.example.mall.domain.BestSellingProducts;
import com.example.mall.dto.BestSellingProductsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.BestSellingProductsQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IBestSellingProductsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bestSellingProducts")
public class BestSellingProductsController {

    @Autowired
    public IBestSellingProductsService bestSellingProductsService;

    /**
     * 分页查询热销商品分析表信息
     * @param bestSellingProductsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询热销商品分析表信息",notes = "分页查询热销商品分析表信息",httpMethod = "GET")
    public JSONResult queryPage(BestSellingProductsQuery bestSellingProductsQuery){
        PageDTO<BestSellingProductsDto> bestSellingProductsDtoPageDTO = bestSellingProductsService.queryPage(bestSellingProductsQuery);
        return JSONResult.success("查询成功",bestSellingProductsDtoPageDTO);
    }

    /**
     * 根据id查询热销商品分析表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询热销商品分析表信息",notes = "根据id查询热销商品分析表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.SELLINGPRODUCTSID_NOT_ID);
        }
        BestSellingProducts bestSellingProducts = bestSellingProductsService.getById(id);
        return JSONResult.success("查询成功",bestSellingProducts);
    }

    /**
     * 根据id查询热销商品分析表信息
     * @param id
     * @return
     */
    @GetMapping("queryBestSellingProductsById/{id}")
    @ApiOperation(value = "根据id查询热销商品分析表信息",notes = "根据id查询热销商品分析表信息",httpMethod = "GET")
    public JSONResult queryBestSellingProductsById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.SELLINGPRODUCTSID_NOT_ID);
        }
        BestSellingProducts bestSellingProducts = bestSellingProductsService.queryBestSellingProductsById(id);
        return JSONResult.success("查询成功",bestSellingProducts);
    }

    /**
     * 查询全部热销商品分析表信息
     * @param
     * @return
     */
    @GetMapping("queryBestSellingProductsList")
    @ApiOperation(value = "查询全部热销商品分析表信息",notes = "查询全部热销商品分析表信息",httpMethod = "GET")
    public JSONResult queryBestSellingProductsList(){
        List<BestSellingProducts> bestSellingProducts = bestSellingProductsService.queryBestSellingProductsList();
        return JSONResult.success("查询成功",bestSellingProducts);
    }

    /**
     * 新增热销商品分析表
     * @param bestSellingProductsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增热销商品分析表",notes = "新增热销商品分析表",httpMethod = "POST")
    public JSONResult insert(@RequestBody BestSellingProductsDto bestSellingProductsDto){
        bestSellingProductsService.insert(bestSellingProductsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改热销商品分析表信息
     * @param bestSellingProductsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改热销商品分析表信息",notes = "修改热销商品分析表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody BestSellingProductsDto bestSellingProductsDto){
        bestSellingProductsService.update(bestSellingProductsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除热销商品分析表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除热销商品分析表信息",notes = "删除热销商品分析表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        bestSellingProductsService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除热销商品分析表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除热销商品分析表信息",notes = "批量删除热销商品分析表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        bestSellingProductsService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
